/**
 * @param {string[]} ops
 * @return {number}
 */
var calPoints = function(ops) {
  function isNum(char) {
    return parseInt(char).toString() !== 'NaN';
  }
  let result = [];
  for(let i = 0; i < ops.length; i++) {
    if(isNum(ops[i])) {
      result.push(parseInt(ops[i]));
    } else {
      switch(ops[i]) {
        case '+':
          result.push(result[result.length - 1] + result[result.length - 2]);
          break;
        case 'D':
          result.push(result[result.length - 1] * 2);
          break;
        case 'C':
          result.pop();
          break;
      }
    }
  }
  let sum = 0;
  for(let i = 0; i < result.length; i++) {
    sum += result[i];
  }
  return sum;
};
let ops = ["5","2","C","D","+"];
console.log(calPoints(ops));
ops = ["5","-2","4","C","D","9","+","+"];
console.log(calPoints(ops));
ops = ["1"];
console.log(calPoints(ops));
